package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

func MyLogger() gin.HandlerFunc {
	return func(c *gin.Context) {
		t := time.Now()

		// 继续执行 原来的逻辑
		c.Next()

		fmt.Printf("耗时：%v \n", time.Since(t))
		status := c.Writer.Status()
		fmt.Printf("status: %v", status)
	}
}

func main(){
	router := gin.Default()
	router.Use(MyLogger())

	router.GET("/", func(c *gin.Context){
		c.JSON(http.StatusOK, gin.H{
			"message": "my middleware test OK!",
		})
	})

	router.Run(":8080")
}